import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login'
import Home from '../views/home'
import welcome from '../views/welcome'
import user from '../views/user/user.vue'
import rights from '../views/power/rights.vue'
import roles from '../views/power/roles.vue'
import goods_cate from '../views/shop/goods_cate'
import goods_parmas from '../views/shop/goods_parmas'
import goods_list from '../views/shop/goods_list'
import addgoods from '../views/shop/addgoods'
import order from '../views/order/order'
import echarts from '../views/echart/echarts'
Vue.use(VueRouter)

  const routes = [
  {
     path:'/login',
     component:login
  },
  {
     path:'',
     redirect:'/login'
  },
  {
      path:'/home',
     component:Home,
     redirect:'/welcome',
     children:[
       {
         path:"/welcome",
         component:welcome
       },
       {
         path:"/user",
         component:user
       },
       {
        path:"/rights",
        component:rights
      },
      {
        path:"/roles",
        component:roles
      },
      {
        path:"/goods_cate",
        component:goods_cate
      },
      {
        path:"/goods_parmas",
        component:goods_parmas
      },
      {
        path:"/goods_list",
        component:goods_list
      },
      {
        path:"/addgoods",
        component:addgoods
      },
      {
        path:"/order",
        component:order
      },
      {
        path:"/echarts",
        component:echarts
      }
     ]
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  if(to.path=='/login') return next()
  let tokenStr = window.sessionStorage.getItem("token")
  if(!tokenStr) return next('/login')
  next()
})

export default router
